﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace vmlModel.Entities
{
    public class OoxmlDoc : vmlObject
    {
 
        public List<wPict> wPicts { get; set; }
        public List<vmlShapeBase> vmlChildernShapes { get; set; }
        public List<vmlGroup> vmlGroups { get; set; }

        public List<vmlShapeType> vmlShapeTypes { get; set; }
        public List<vmlShape> vmlShapes
        {
            get
            {
                return (from s in vmlChildernShapes
                        where s.GetType() == typeof(vmlShape)
                        select (vmlShape)s).ToList();
            }
        }
     
        #region "predefined shapes"
        public List<vmlRoundrect> vmlRoundrects {
            get
            {
                return (from s in vmlChildernShapes
                        where s.GetType() == typeof(vmlRoundrect)
                        select (vmlRoundrect)s).ToList();
            }

        }
        public List<vmlRect> vmlRects 
        {
          get
            { 
            return (from s in vmlChildernShapes
                      where s.GetType() == typeof(vmlRect)
                        select (vmlRect)s).ToList(); 
            }
        }
        public List<vmlPolyline> vmlPolylines
        {
            get
            {
                return (from s in vmlChildernShapes
                        where s.GetType() == typeof(vmlPolyline)
                        select (vmlPolyline)s).ToList();
            }
        }
        public List<vmlLine> vmlLines
        {
            get
            {
                return (from s in vmlChildernShapes
                        where s.GetType() == typeof(vmlLine)
                        select (vmlLine)s).ToList();
            }
        }
        public List<vmlArc> vmlArcs
        {
            get
            {
                return (from s in vmlChildernShapes
                        where s.GetType() == typeof(vmlArc)
                        select (vmlArc)s).ToList();
            }
        }
        public List<vmlCurve> vmlCurves
        {
            get
            {
                return (from s in vmlChildernShapes
                        where s.GetType() == typeof(vmlCurve)
                        select (vmlCurve)s).ToList();
            }
        }
        public List<vmlOval> vmlOvals
        {
            get
            {
                return (from s in vmlChildernShapes
                        where s.GetType() == typeof(vmlOval)
                        select (vmlOval)s).ToList();
            }
        }

        #endregion

        public OoxmlDoc()
        {
            IntializeChildern();
        }
        public OoxmlDoc(XElement _vmlObjElement) : base( _vmlObjElement)
        {
            IntializeChildern();
            FillMe();
        }

        private void IntializeChildern()
        {
            wPicts = new List<wPict>();
            vmlChildernShapes = new List<vmlShapeBase>(); 
            vmlGroups = new List<vmlGroup>();
            vmlShapeTypes = new List<vmlShapeType>();
        }
        private void FillMe()
        {
            // get the picts
            foreach (XElement pict in from pict in vmlObjElement
                           .Descendants(vmlUtils.w + "p")
                           .Descendants(vmlUtils.w + "r")
                           .Descendants(vmlUtils.w + "pict")
                     select pict)
            { 
             wPicts.Add(new wPict(this , pict)); 
            }
            //get drawing
            
            //get paragraphs

        }

    }

}
